namespace CSharpPro._0930;

public class Demo
{
        // 1. 三个整数由小到大输出
        public static void SortThreeNumbers()
        {
            Console.WriteLine("请输入第一个整数x：");
            int x = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入第二个整数y：");
            int y = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入第三个整数z：");
            int z = int.Parse(Console.ReadLine());

            int temp;
            if (x > y) { temp = x; x = y; y = temp; }
            if (x > z) { temp = x; x = z; z = temp; }
            if (y > z) { temp = y; y = z; z = temp; }

            Console.WriteLine($"从小到大输出：{x}, {y}, {z}");
        }

        // 2. 打印1-100之间不是7的倍数且不包含7的数字并求和
        public static void PrintAndSumNumbers()
        {
            int sum = 0;
            for (int i = 1; i <= 100; i++)
            {
                if (i % 7 != 0 && !i.ToString().Contains("7"))
                {
                    Console.Write($"{i} ");
                    sum += i;
                }
            }
            Console.WriteLine($"\n这些数的和为：{sum}");
        }

        // 3. 打印九九乘法表
        public static void PrintMultiplicationTable()
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write($"{j}×{i}={i * j}\t");
                }
                Console.WriteLine();
            }
        }

        // 4. 找出1000以内的所有完数
        public static void FindPerfectNumbers()
        {
            Console.WriteLine("1000以内的完数有：");
            for (int i = 1; i < 1000; i++)
            {
                int sum = 0;
                for (int j = 1; j < i; j++)
                {
                    if (i % j == 0)
                        sum += j;
                }
                if (sum == i)
                    Console.WriteLine(i);
            }
        }

        // 5. 分析正整数的位数并逆序打印各位数字
        public static void AnalyzeInteger()
        {
            Console.WriteLine("请输入一个正整数：");
            string numStr = Console.ReadLine();
            int digitCount = numStr.Length;
            Console.WriteLine($"它是{digitCount}位数");
            Console.WriteLine("逆序打印各位数字：");
            for (int i = digitCount - 1; i >= 0; i--)
            {
                Console.Write(numStr[i] + " ");
            }
            Console.WriteLine();
        }

        // 6. 根据输入行数打印菱形
        public static void PrintDiamond()
        {
            Console.WriteLine("请输入菱形的行数（奇数）：");
            int n = int.Parse(Console.ReadLine());
            int half = n / 2;

            // 上半部分
            for (int i = 0; i <= half; i++)
            {
                for (int j = 0; j < half - i; j++)
                    Console.Write(" ");
                for (int j = 0; j < 2 * i + 1; j++)
                    Console.Write("*");
                Console.WriteLine();
            }

            // 下半部分
            for (int i = half - 1; i >= 0; i--)
            {
                for (int j = 0; j < half - i; j++)
                    Console.Write(" ");
                for (int j = 0; j < 2 * i + 1; j++)
                    Console.Write("*");
                Console.WriteLine();
            }
        }
    
}